import * as redis from 'redis';

export class PubSubClient {
  client: any;

  initialize(
    option: {host: string; port: number; password: string; database: string} = {
      host: 'localhost',
      port: 6379,
      password: '',
      database: ''
    }
  ): void {
    const client = redis.createClient(option);

    client.on('connect', () => {
      return console.log('redis connected!');
    });

    if (option.database) {
      client.select(option.database);
    }

    client.on('error', err => {
      console.log('Error ' + err);
    });

    this.client = client;
  }
}

const defaultPubsubClient = new PubSubClient();

export default defaultPubsubClient;
